#include <Singleton.h>

int main()
{
    try
    {
        std::thread th1([](){
            std::cout << "th1" << std::endl;
            Singleton &s = Singleton::GetInstance();
            s.Initial();
    });
        std::future<Num> f = Singleton::GetInstance().sp_.get_future();
        std::future_status fs = f.wait_for(std::chrono::milliseconds(1000));
        if (fs == std::future_status::ready)
        {
            std::cout <<" get() =" << f.get().first_ << std::endl;
        } 
        else
        {
            std::cout << "I am not fun" <<std::endl;
        } 
        th1.join();
   }
   catch(const std::exception& e)
   {
       std::cerr << e.what() << '\n';
   }
    return 0;
}

// using namespace std;
// int main()
// {
//     std::promise<int> prom;
//     //std::future<int> fut = prom.get_future();
//     auto retFut = std::async(std::launch::async, [prom = std::move(prom)] () mutable {
//         cout << "In child" << endl;
//         // prom.set_value(4); //<-- Shouldn't not having this line cause the exception
//         return 4;
//     });

//     int childValue = retFut.get();
//     cout << "Child has set the value: " << childValue << endl;
//     return 0;
// }

// void DoSomething(std::future<int>&& fut)
// {
//     cout << "Waiting for parent to send a value " << endl;
//     int val = fut.get();

//     cout << "Parent sent value " << val << endl;
// }

// int main()
// {
//     std::promise<int> prom;
//     std::future<int> fut = prom.get_future();
//     auto retFut = std::async(std::launch::async, DoSomething, std::move(fut));
//     prom.set_value(3); // <-- This should cause the exception?
//     return 0;
// }
